/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.service.loan;

import com.server.common.persistence.Page;
import com.server.common.service.CrudService;
import com.server.modules.sys.dao.loan.LoanManagerDao;
import com.server.modules.sys.entity.loan.LoanManager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 产品经理管理Service
 * @author 王磊
 * @version 2016-09-07
 */
@Service
@Transactional(readOnly = true)
public class LoanManagerService extends CrudService<LoanManagerDao, LoanManager> {

	public LoanManager get(String id) {
		return super.get(id);
	}
	
	public List<LoanManager> findList(LoanManager loanManager) {
		return super.findList(loanManager);
	}
	
	public Page<LoanManager> findPage(Page<LoanManager> page, LoanManager loanManager) {
		return super.findPage(page, loanManager);
	}
	
	@Transactional(readOnly = false)
	public void save(LoanManager loanManager) {
		super.save(loanManager);
	}
	
	@Transactional(readOnly = false)
	public void delete(LoanManager loanManager) {
		super.delete(loanManager);
	}
	@Transactional(readOnly = false)
    public boolean deleteByLoanId(String loanId) {
		//参数校验
		if(StringUtils.isBlank(loanId)){
			return false;
		}
		return dao.deleteByLoanId(loanId)>0?true:false;
    }
	public List<LoanManager> getByLoanId(String loanId) {
		//参数校验
		if(StringUtils.isBlank(loanId)){
			return null;
		}
		return dao.getByLoanId(loanId);
	}
	@Transactional(readOnly = false)
	public boolean saveByLoanId(String loanId, String[] managers) {
		//参数校验
		if(StringUtils.isBlank(loanId)||managers==null){
			return false;
		}
		//先删除之前的关系 再保存（避免出现重复插入的现象  这样效率稍微低一点，但这种操作不会太频繁，可以这样）
		this.deleteByLoanId(loanId);
		for (String manager : managers) {
			LoanManager loanManager=new LoanManager();
			loanManager.setLoanId(loanId);
			loanManager.setUserId(manager);
			this.save(loanManager);
		}
		return true;
	}
}